RE: [GENERAL] How to get seq after insert

Поиск
Список
Период
Сортировка
От Herouth Maoz
Тема RE: [GENERAL] How to get seq after insert
Дата
Msg-id l03130300b3420eefc12a@[147.233.159.109]
обсуждение исходный текст
Ответ на RE: [GENERAL] How to get seq after insert  (Michael Davis <michael.davis@tvguide.com>)
Список pgsql-general
At 00:39 +0300 on 15/04/1999, Michael Davis wrote:


> The safest way is to select the nextval('seq_name') and then insert using
> this value.

No, actually, this is the unsafest way. This means that the logic is in the
frontend, not the backend. Besides, one can define the sequence as
read-only for the user who uses the database, but write for the one who
created the table that uses it, so that the user can't change the sequence
out of line.

To make a long story short, the best way is to let the insert statement use
the defaulet, and then use currval( 'seq_name' ). This gives you the last
value given in the current session. It is multiuser-safe, etc.

This was on the SQL list a couple of weeks ago. And by the way, the SQL
list is the proper list for this issue.

Herouth

--
Herouth Maoz, Internet developer.
Open University of Israel - Telem project
http://telem.openu.ac.il/~herutma



В списке pgsql-general по дате отправления:

Предыдущее
От: Valerio Santinelli
Дата:
Сообщение: Re: [GENERAL] pg_dumpall troubles
Следующее
От: Karl DeBisschop
Дата:
Сообщение: Re: [GENERAL] problem when vacuuming. . .